package snackfind.sjoerd.job;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class Maps extends MapActivity {
	boolean streetsat = true;
    MapView mapView; 
    MapController mc;
    GeoPoint p;
    
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle extras = getIntent().getExtras();
        boolean MAC_WAARDE = extras.getBoolean("macwaarde");
        setContentView(R.layout.googlemaps); 
  
       
        
        mapView = (MapView) findViewById(R.id.mapView);
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
        View zoomView = mapView.getZoomControls(); 
 
        zoomLayout.addView(zoomView, 
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(true);
        mapView.setStreetView(true);
        mapView.setSatellite(false);
        
        mc = mapView.getController();
        String coordinates[] = {"51.909896","4.462416"};
        
        mc.animateTo(gpslocatie(coordinates[0],coordinates[1]));
        mc.setZoom(14);
        mapView.invalidate();
        
        //---Add a location marker---
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.mcdonalds_logo);
        IconOverlay itemizedoverlay = new IconOverlay(drawable,this);
        
        //if(mcd){
        
        String mac_1 = "Hoogstraat 194"+
        		"\n" +
        		"3011 PV" +
        		"\n" +
        		"Rotterdam";

        GeoPoint point = gpslocatie("51.92046", "4.48342");
        OverlayItem overlayitem = new OverlayItem(point, "Info", "" + mac_1);
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
       // }
        
        final Button button = (Button) findViewById(R.id.streetsatelietview);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	if(streetsat){
            		mapView.setStreetView(false);
            		mapView.setSatellite(true);
            		streetsat=false;
            		button.setText("MapView");
            	}
            	else{
            		mapView.setStreetView(true);
            		mapView.setSatellite(false);
            		streetsat=true;
            		button.setText("SatelietView");
            	}
            		
            }
        });
    }
    
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    
    public static GeoPoint gpslocatie(String lat1, String lot1){
    	double lat = Double.parseDouble(lat1);
        double lng = Double.parseDouble(lot1);
        
        GeoPoint p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));
        return p;
    }
}